import router from './router'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import { getToken } from '@/utils/auth' // getToken from cookie
// 不需要TOKNE的页面
NProgress.configure({ showSpinner: false }) // NProgress Configuration

router.beforeEach(async(to, from, next) => {
  // start progress bar
  NProgress.start()
  if (to.path === '/') {
    next({ path: '/account/login' })
    return
  }
  const token = getToken()
  console.log(111, token)
  if (!token) {
    if (to.name === 'Login') {
      next()
    } else {
      next({ path: '/account/login' })
      return
    }
    return
  }
  next()
})

router.afterEach(() => {
  // finish progress bar
  NProgress.done()
})
